/**
 * 系统后台资源树服务管理JS-groupList.jsp
 */
//项目路径
var strPath = window.document.location.pathname;
//var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
var postPath = "/gdp";
var editstate = "";
var syseditstate = "";

//判断是否采用顶级节点
var isnode = "";

var idid = ""

var pidpid = "";

var dbids = "";

var cc = 0;

var editStarts = 0;

var parguid = 0;

var xs = "";

//判断是添加还是保存
var editStart = 1;

var iso = "";
//参数0
$("#hid_servertype").val(GetQueryString("servertype"));//服务类型 添加使用
$("#hid_operate").val(GetQueryString("operate")); //操作类型
$("#hid_serviceId").val(GetQueryString("servercode"));//服务ID  修改使用
$("#hid_projectid").val(GetQueryString("projectid"));//工程ID 添加修改预留
$(function () {
    $("#cengjiid").hide();
    $("#EditContent").hide();
    $("#cengjiming").hide();
    $("#btn_addtree").hide();
    $("#dbkey").attr("readonly", false);
    $("#chaxunzd").hide();
    $("#tablename").select2();

    //资源树树形操作方法--------------------------------------------
    function showDbkey() {
        $.ajax({
            type: 'get',
            // url : postPath + '/system/treeConfig/getTreeList',
            url: postPath + '/system/sysProject/getProjectToDataSource?pcode=' + GetQueryString("projectid"),
            async: false,
            success: function (res) {
                $("#dbkey").append('');
                var strtxt = "<option value=''>请选择</option>";
                if (res.success) {
                    $.each(res.data, function (i, e) {
                        strtxt += "<option value='" + e.dbKey + "'>" + e.dbMark + "(" + e.dbKey + ")" + "</option>";
                    });
                }
                $("#dbkey").html(strtxt);
            },
            error: function () {
                alert('error...');
            }
        });
    }

    showDbkey();

    //判断服务修改还是添加
    if ($("#hid_operate").val() == "edit") {
        iso = $("#hid_serviceId").val();
        $("#tb_dataList").bootstrapTable('refresh');
        GetTableList();
        dbids = $("#hid_serviceId").val();
        $("#tab_1_1_1").show();
        $("#tab_1_1_2").hide();
    }

    if ($("#hid_operate").val() == "add") {
        cleanContented();
        $("#treeids").attr("readonly", false);
        $("#isfemale").attr('checked', 'checked');
        $("#ismales").attr('checked', 'checked');
        $("#topname").attr("disabled", true);
        $("#catchtime").attr("disabled", true);
        editStart = 1;
        $("#tab_1_1_1").show();
        $("#tab_1_1_2").hide();
    }
    // 左侧tree数据绑定
    var setting = {
        data: {
            key: {
                title: "hint"
            },
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: onClick
        }
    };
    var zNodes = GetLeftTreeData();
    $.fn.zTree.init($("#tree"), setting, zNodes);

    function locationTab() {
        $('#myTab a[href="#tab_1_1_1"]').tab('show');
    }

    // Tree点击事件
    function onClick(event, treeId, treeNode, clickFlag) {
        $("#dingji").show();
        $("#btn_addtree").hide();
        idid = treeNode.id;
        pidpid = treeNode.pid;
        locationTab();
        if (pidpid != 0) {
            $("#dbkey").val(treeNode.pidpid);
            $("#tb_dataList").bootstrapTable('refresh');
            GetTableList();
            dbids = pidpid;
            $("#tab_1_1_1").show();
            $("#tab_1_1_2").hide();
        } else {
            cleanContented();
            $("#dbkey").val(idid);
            $("#treeids").attr("readonly", false);
            $("#ismale").attr('checked', 'checked');
            $("#ismales").attr('checked', 'checked');
            editStart = 1;
            dbids = idid;
            $("#tab_1_1_1").show();
            $("#tab_1_1_2").hide();
        }
    }

    $("#ismale").change(function () {
        $("#dingji").show();
        $("#topname").val("");
    });

    //查看树节点详情
    function GetTableList() {
        cleanContented();
        $.ajax({
            type: 'get',
            url: postPath + '/system/treeConfig/selectTreeFile',
            data: {
                sysId: iso
            },
            async: false,
            success: function (res) {
                editStart = 2;
                idid = iso;
                pidpid = res.dtDbKey;
                $("#treeids").attr("readonly", "readonly");
                $("#treeids").val(res.guid);
                $("#servicename").val(res.servicename);
                $("#dbkey").val(res.dtDbKey);
                $("#catchtime").val(res.catchtime);
                if (res.islazyload == 1) {
                    $("#ismales").attr('checked', 'checked');
                }
                if (res.islazyload == 0) {
                    $("#isfemales").attr('checked', 'checked');
                }
                if (res.isusetop == 1) {
                    $("#ismale").attr('checked', 'checked');
                }
                if (res.isusetop == 0) {
                    $("#isfemale").attr('checked', 'checked');
                }
                if (res.iscatch == 1) {
                    $("#males").attr('checked', 'checked');
                    $("#catchtime").removeAttr("disabled");
                }
                if (res.iscatch == 0) {
                    $("#females").attr('checked', 'checked');
                    $("#catchtime").attr("disabled", "disabled");
                }
                if (res.isusetop == 0) {
                    $("#dingji").hide();
                } else {
                    $("#topname").val(res.topnode);
                }
            },
            error: function () {
                alert('出错了...........');
            }

        });
    }

    $("input[name='istop']").change(function () {
        var value = $(this).val();
        if (value == '1') {
            $("#topname").removeAttr("disabled");
            $("#topname").val("");
        } else if (value == '0') {
            $("#topname").val("");
            $("#topname").attr("disabled", true);
        }
    });
    $("input[name='catcheds']").change(function () {
        var value = $(this).val();
        if (value == '1') {
            $("#catchtime").removeAttr("disabled");
            $("#catchtime").val("");
        } else if (value == '0') {
            $("#catchtime").val("");
            $("#catchtime").attr("disabled", true);
        }
    });
    $("#deletetree").click(function () {
        if (pidpid == 0) {
            // bootbox.alert("请选择要删除的资源树节点!");
            showMsg("请选择要删除的资源树节点!", "warning");
            return;
        }
        $.ajax({
            type: 'get',
            url: postPath + '/system/treeConfig/deleteTreeExt',
            async: false,
            data: {keyid: idid},
            success: function (res) {
                // bootbox.alert("删除成功!");
                showMsg("删除成功!", "success");
                $('#tb_dataList').bootstrapTable('refresh');
                cleanContented();
            },
            error: function () {
                // alert('删除失败');
                showMsg("删除失败!", "error");
            }
        });
    });

    // 获取左侧列表数据
    function GetLeftTreeData() {
        var treeData;
        $.ajax({
            type: 'get',
            url: postPath + '/system/treeConfig/getTreeList',
            async: false,
            success: function (res) {
                treeData = res;
            },
            error: function () {
                alert('error...');
            }
        });
        return treeData;
    }

    //删除资源树操作
    $("#deletety").click(function () {
        if (pidpid == 0) {
            // bootbox.alert("禁止删除数据库!");
            showMsg("禁止删除数据库!", "error");
            return;
        }
        bootbox.confirm("确认删除?", function (result) {
            if (result == false)
                return;
            $.ajax({
                url: postPath + '/system/treeConfig/deleteTreeConfig',
                type: 'get',
                data: {
                    keys: idid
                },
                success: function (data) {
                    // bootbox.alert("删除成功!");
                    showMsg("删除成功!", "success");
                    cleanContented();
                    var zNodes = GetLeftTreeData();
                    $.fn.zTree.init($("#tree"), setting, zNodes);
                    $('#tree').bootstrapTable('refresh');
                },
                error: function () {
                    showMsg("删除失败!", "error");
                    // bootbox.alert("删除失败!");
                }
            });
        });
    });
    //保存操作
    $("#btn_dsave").click(function () {
        var validataResult = validates();
        if (validataResult) {
            var editurl = "";
            if (editStart == 1) {
                editurl = postPath + '/system/treeConfig/insertTreeList';
            } else if (editStart == 2) {
                editurl = postPath + '/system/treeConfig/updateTreeList';
            }
            var serverdb = "";
            if (editStart == 1) {
                serverdb = {
                    guid: $("#treeids").val(),
                    servicename: $("#servicename").val(),
                    dtDbKey: $("#dbkey").val(),
                    islazyload: $("input[name='islazy']:checked").val(),
                    isusetop: $("input[name='istop']:checked").val(),
                    topnode: $("#topname").val(),
                    iscatch: $("input[name='catcheds']:checked").val(),
                    catchtime: $("#catchtime").val(),
                    hidServertype: $("#hid_servertype").val(),
                    hidProjectid: $("#hid_projectid").val()

                };
            }
            if (editStart == 2) {
                serverdb = {
                    guid: $("#treeids").val(),
                    servicename: $("#servicename").val(),
                    dtDbKey: $("#dbkey").val(),
                    islazyload: $("input[name='islazy']:checked").val(),
                    isusetop: $("input[name='istop']:checked").val(),
                    topnode: $("#topname").val(),
                    iscatch: $("input[name='catcheds']:checked").val(),
                    catchtime: $("#catchtime").val()

                };
            }

            $.ajax({
                type: 'POST',
                url: editurl,
                data: JSON.stringify(serverdb),
                dataType: 'json',
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {
                    // bootbox.alert("保存成功!");
                    showMsg("保存成功!", "success");
                    idid = $("#treeids").val();
                    var zNodes = GetLeftTreeData();
                    $.fn.zTree.init($("#tree"), setting, zNodes);
                    $('#tree').bootstrapTable('refresh');
                    iso = $("#treeids").val();
                    dbids = $("#dbkey").val();
                    pidpid = dbids;
                    showTableName();
                }
            });

        }

    });
    $("#btn_save").click(function () {
        var validataResult = validateData();
        if (validataResult) {
            var editurl = "";
            if (editstates == 1) {
                editurl = postPath + '/system/treeConfig/insertTreeNode';
            } else if (editstates == 2) {
                editurl = postPath + '/system/treeConfig/updateTreeNode';
            }
            var serverdb = "";
            if (editstates == 2) {
                serverdb = {
                    treename: $("#cenname").val(),
                    guid: $("#cenguid").val(),
                    serviceid: idid,
                    queryCon: $("#biaocolumn").val(),
                    dtConfigId: $("#tablename option:selected").val(),
                    grade: $("#treeceng option:selected").val(),
                    fieldKey: $("#biaoid option:selected").val(),
                    fieldPKey: $("#biaopid option:selected").val(),
                    fieldShow: $("#biaoname option:selected").val()
                };
            }
            if (editstates == 1) {
                serverdb = {
                    treename: $("#cenname").val(),
                    parentguid: cc,
                    serviceid: idid,
                    queryCon: $("#biaocolumn").val(),
                    dtConfigId: $("#tablename option:selected").val(),
                    grade: $("#treeceng option:selected").val(),
                    fieldKey: $("#biaoid option:selected").val(),
                    fieldPKey: $("#biaopid option:selected").val(),
                    fieldShow: $("#biaoname option:selected").val()
                };
            }
            $.ajax({
                type: 'POST',
                url: editurl,
                async: false,
                data: JSON.stringify(serverdb),
                dataType: 'json',
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {
                    // bootbox.alert("保存成功!");
                    showMsg("保存成功!", "success");
                    $("#btn_addtree").hide();
                    getListser();
                    $("#EditContent").modal('hide');
                }
            });

        }

    });

    $("#a_tab_column").click(function () {
        // bootbox.alert("请选择服务!");
        showMsg("请选择服务!", "warning");
        $("#btn_addtree").show();
        getListser();
        $("#tab_1_1_2").show();
        $("#tab_1_1_1").hide();
        $("#tab_1_1_4").hide();
        setTimeout(locationTab2, 200);
        return;
    });

    //返回列表
    $("#btn_back").click(function () {
        window.location.href = postPath + "/prjService/index";
    });
    $("#a_tab_table").click(function () {
        $("#btn_addtree").hide();
        $("#tab_1_1_1").show();
        $("#tab_1_1_2").hide();
        if (iso != "") {
            $("#dbkey").val(pidpid);
            $("#tb_dataList").bootstrapTable('refresh');
            GetTableList();
            dbids = pidpid;
            $("#tab_1_1_1").show();
            $("#tab_1_1_2").hide();
        } else {
            cleanContented();
            $("#dbkey").val(idid);
            $("#treeids").attr("readonly", false);
            $("#ismale").attr('checked', 'checked');
            $("#ismales").attr('checked', 'checked');
            editStart = 1;
            dbids = idid;
        }
    });

    $("#a_fieldconfig_2_2").click(function () {
        locationcolumn();
        getFieldListing();
        $("#tab_1_1_5").hide();
        $("#tab_1_1_1").hide();
        $("#tab_1_1_2").hide();
        //$("#tab_1_1_3").show();
        $("#tab_2_1").hide();
        $("#tab_2_2").show();
    });
    //配置顶级节点
    $("#btn_addtree").click(function () {
        if (iso == "") {
            // bootbox.alert("请先配置服务!");
            showMsg("请先配置服务!", "warning");
            $("#treeids").attr("readonly", false);
            $("#btn_addtree").hide();
            $("#tb_dataList").bootstrapTable('refresh');
            GetTableList();
            $("#dbkey").val(idid);
            dbids = pidpid;
            $("#tab_1_1_2").hide();
            $("#tab_1_1_1").show();
            $("#tab_1_1_4").hide();
            setTimeout(locationTab, 200);
            return;
        }
        cc = 0;
        cleantreecontent();
        showTableName();
        editstates = 1;
        $("#EditContent").modal('show');
    });
    $("#a_tab_field").click(function () {
        $("#btn_addtree").show();
        getListser();
    });
    //选择表名的点击事件
    $("#tablename").change(function () {
        $("#biaoid").empty();
        $("#biaoname").empty();
        $("#biaopid").empty();
        var checkValue = $("#tablename").val();
        if (checkValue == 0) {
            return;
        }
        var pids = 0;
        if (pidpid != 0) {
            pids = pidpid;
        } else {
            pids = idid;
        }
        $.ajax({
            type: 'get',
            url: postPath + '/system/treeConfig/selectTableColumn',
            async: false,
            data: {
                dbid: checkValue,
                dbkey: pids
            },
            success: function (res) {
                apen = "";
                $("#biaoid").append("<option value=''>请选择字段</option>");
                $("#biaoname").append("<option value=''>请选择字段</option>");
                $("#biaopid").append("<option value=''>请选择字段</option>");
                $.each(res, function (is, el) {
                    $("#biaoid").append("<option value=" + is + ">" + el + "</option>");
                    $("#biaoname").append("<option value=" + is + ">" + el + "</option>");
                    $("#biaopid").append("<option value=" + is + ">" + el + "</option>");
                });
            }
        });
    });

    function showTableName() {

        $.ajax({
            type: 'get',
            url: postPath + '/system/treeConfig/selectAllTable',
            async: false,
            data: {
                dbid: pidpid
            },
            success: function (res) {
                $("#tablename").append(
                    "<option value=0>请选择配置表名</option>");
                $.each(res, function (i, e) {
                    $("#tablename").append(
                        "<option value=" + i + ">" + e + "</option>");
                });
            }
        });
    }
})

//资源树验证表单------------------------------------------------------------------------------------
function validates() {
    if ($("#dbkey").val() == "") {
        // bootbox.alert("请选择数据库!");
        showMsg("请选择数据库!", "warning");
        return false;
    } else {
        if ($("#treeids").val() == "") {
            $("#derrorInfo").html("服务ID不能为空");
            return false;
        } else {
            $("#derrorInfo").html("");
        }
        if ($("#servicename").val() == "") {
            $("#derrorInfo").html("树服务名不能为空");
            return false;
        } else {
            $("#derrorInfo").html("");
        }
        var nodeing = $("input[name='istop']:checked").val();
        if (nodeing == 1) {
            if ($("#topname").val() == "") {
                $("#derrorInfo").html("顶级节点名称不能为空!");
                return false;
            } else {
                $("#derrorInfo").html("");
            }
        }
        var iscatch = $("input[name='catcheds']:checked").val();
        if (iscatch == 1) {
            if ($("#catchtime").val() == "") {
                $("#derrorInfo").html("缓存时间不能为空!");
                return false;
            } else {
                $("#derrorInfo").html("");
            }
        }
        var re = 0;
        if (editStart == 1) {
            var selectguid = $("#treeids").val();
            $.ajax({
                type: 'get',
                url: postPath + '/system/treeConfig/selectCountGUID',
                async: false,
                data: {
                    dbKey: selectguid
                },
                success: function (res) {
                    re = res;
                }
            });
        }
        if (re != 0) {
            $("#derrorInfo").html("树服务ID在表中已存在");
            return false;
        } else {
            $("#derrorInfo").html("");
        }
        return true;
    }

}

//默认加载数据
function getList() {
    $(".tree-2 tbody").html("");
    $.ajax({
        type: 'get',
        url: postPath + '/system/treeConfig/selectTreeshow',
        data: {
            sysId: idid,
            keys: pidpid
        },
        success: function (res) {
            var strtd = "";
            $.each(res, function (i, e) {
                var aa = 0;
                var bb = 0;
                aa = Number(e.guid);
                bb = Number(e.parentguid);
                if (aa == 0) {
                    strtd += "<tr class='treegrid-" + aa + "'>";
                } else {
                    strtd += "<tr class='treegrid-" + aa + " treegrid-parent-" + bb + "'>";
                }
                strtd += "<td>" + (e.dtConfigId == null ? "" : e.dtConfigId) + "</td><td>" + (e.fieldKey == null ? "" : e.fieldKey) + "</td><td>" + (e.fieldShow == null ? "" : e.fieldShow) + "</td><td>" + (e.fieldPKey == null ? "" : e.fieldPKey) + "</td><td>" + (e.queryCon == null ? "" : e.queryCon) + "</td><td>" + e.grade + "</td>";
                strtd += "<td><a href='javascript:;' onclick='addClick(" + e.guid + ");' class='btn btn-default btn-sm'><i class='fa fa-plus'></i></a>";
                strtd += "<a href='javascript:;' onclick='updateClick(" + e.guid + ");' class='btn btn-default btn-sm'><i class='fa fa-edit'></i> </a> ";
                strtd += " <a href='javascript:;' onclick='delClick(" + e.guid + ");' class='btn btn-default btn-sm'><i class='fa fa-remove'></i> ";
                strtd += " </a></td></tr>";
            });
            $(".tree-2 tbody").append(strtd);
        }
    });
    $('.tree-2').treegrid({
        expanderExpandedClass: 'glyphicon glyphicon-minus',
        expanderCollapsedClass: 'glyphicon glyphicon-plus'
    });
}

function getListser() {
    $("#tab_1_1_1").hide();
    $("#tab_1_1_2").show();
    $(".tree-2 tbody").html("");
    var serverdb = {
        sysId: idid,
        keys: pidpid
    };
    $.ajax({
        type: 'POST',
        url: postPath + '/system/treeConfig/selectTreeshow',
        async: false,
        data: JSON.stringify(serverdb),
        dataType: 'json',
        contentType: "application/json",
        success: function (res) {
            if (res.length == 0) {
                $("#btn_addtree").show();
            } else {
                $("#btn_addtree").hide();
            }
            var strtd = "";
            $.each(res, function (i, e) {
                var xx = e.serviceid;
                xx = xx + "," + e.grade + ",3";
                xx = '"' + xx + '"';
//        		alert(e.guid);
//        		alert(xx);
                if (e.parentguid == 0) {
                    strtd += "<tr class='treegrid-" + e.guid + "'>";
                } else {
                    strtd += "<tr class='treegrid-" + e.guid + " treegrid-parent-" + e.parentguid + "'>";
                }
                strtd += "<td>" + (e.dtConfigId == null ? "" : e.dtConfigId) + "</td><td>" + (e.fieldKey == null ? "" : e.fieldKey) + "</td><td>" + (e.fieldShow == null ? "" : e.fieldShow) + "</td><td>" + (e.fieldPKey == null ? "" : e.fieldPKey) + "</td><td>" + e.grade + "</td>";
                strtd += "<td><a href='javascript:;' onclick='addClick(" + e.guid + ");' class='btn btn-default btn-sm'><i class='fa fa-plus'></i></a>";
                strtd += "<a href='javascript:;' onclick='updateClick(" + e.guid + ");' class='btn btn-default btn-sm'><i class='fa fa-edit'></i> </a> ";
                strtd += " <a href='javascript:;' onclick='delClick(" + e.guid + ");' class='btn btn-default btn-sm'><i class='fa fa-remove'></i> </a>";
                strtd += "<a href='javascript:;' onclick='showtableClick(" + xx + ");' class='btn btn-default btn-sm'>查询字段 </a> ";
                strtd += " </a></td></tr>";
            });
            $(".tree-2 tbody").append(strtd);
        }
    });
    $('.tree-2').treegrid({
        expanderExpandedClass: 'glyphicon glyphicon-minus',
        expanderCollapsedClass: 'glyphicon glyphicon-plus'
    });
}

function addClick(c) {
    cc = c;
    cleantreecontent();
    showTableName();
    editstates = 1;
    $("#EditContent").modal('show');
}

//修改操作
function updateClick(groupid) {
    //alert(xs);
    cleantreecontent();
    showTableName();
    editstates = 2;
    $.ajax({
        type: 'get',
        url: postPath + '/system/treeConfig/selectOneTree',
        async: false,
        data: {
            dbid: groupid
        },
        success: function (res) {
            showColumn(res.dtConfigId);
            $("#cenguid").val(res.guid);
            $("#cenname").val(res.treename);
            $('#biaocolumn').val(res.queryCon);
            $('select#tablename').val(res.dtConfigId).trigger("change");
            $('select#treeceng').val(res.grade);
            $('select#biaoid').val(res.fieldKey);
            $('select#biaopid').val(res.fieldPKey);
            $('select#biaoname').val(res.fieldShow);
            $("#EditContent").modal('show');
        }
    });
}

function showtableClick(a) {
    locationTab4();
    var psp = a.split(",");
    //psp[0]= '"'+psp[0]+'"';
    var frameSrc = postPath + "/queryConditionConfig/index?serviceId=" + psp[0] + "&serviceType=3&grade=" + psp[1];
    $("#queryIframe").attr("src", frameSrc);
    $("#btn_addtree").hide();
    $("#tab_1_1_1").hide();
    $("#tab_1_1_2").hide();
    $("#tab_1_1_4").show();
}

function delClick(c) {
    bootbox.confirm("确认删除?", function (result) {
        if (result == false)
            return;
        $.ajax({
            url: postPath + '/system/treeConfig/deleteTreeNode',
            type: 'get',
            data: {idss: c, treeid: idid, seid: pidpid},
            success: function (res) {
                // bootbox.alert("删除成功!");
                showMsg("删除成功!", "success");
                getListser();
                $("#EditContent").modal('hide');
            },
            error: function () {
                // bootbox.alert("删除失败!");
                showMsg("删除失败!", "error");
            }
        });
    });
}

//选择表名的点击事件
function showColumn(sb) {
    var checkValue = sb;
    if (checkValue == 0) {
        return;
    }
    var pids = 0;
    if (pidpid != 0) {
        pids = pidpid;
    } else {
        pids = idid;
    }
    $.ajax({
        type: 'get',
        url: postPath + '/system/treeConfig/selectTableColumn',
        async: false,
        data: {
            dbid: checkValue,
            dbkey: pids
        },
        success: function (res) {
            apen = "";
            $.each(res, function (is, el) {
                $("#biaoid").append("<option value=" + is + ">" + el + "</option>");
                $("#biaoname").append("<option value=" + is + ">" + el + "</option>");
                $("#biaopid").append("<option value=" + is + ">" + el + "</option>");
            });
        }
    });
}

function showTableName() {

    $.ajax({
        type: 'get',
        url: postPath + '/system/treeConfig/selectAllTable',
        async: false,
        data: {
            dbid: pidpid
        },
        success: function (res) {
            $("#tablename").append(
                "<option value=0>请选择配置表名</option>");
            $.each(res, function (i, e) {
                $("#tablename").append(
                    "<option value=" + i + ">" + e + "</option>");
            });
        }
    });
}

function cleanContented() {
    // 维护内容清空
    $("#servicename").val("");
    $("#treeids").val("");
    $("#topname").val("");
    $("#catchtime").val("");

    // 验证信息清空
    $("#derrorInfo").html("");


}

function validateData() {

    if ($("#tablename option:selected").val() == 0) {
        $("#valide_tablename").html("配置表名不能为空!");
        return false;
    } else {
        $("#valide_tablename").html("");
    }
    if ($("#biaoid option:selected").val() == "") {
        $("#valide_biaoid").html("配置表ID字段不能为空!");
        return false;
    } else {
        $("#valide_biaoid").html("");
    }
    if ($("#biaoname option:selected").val() == "") {
        $("#valide_biaoname").html("配置表NAME字段不能为空!");
        return false;
    } else {
        $("#valide_biaoname").html("");
    }
    if (cc != 0) {
        if ($("#biaopid option:selected").val() == "") {
            $("#valide_biaopid").html("关联PID字段不能为空!");
            return false;
        } else {
            $("#valide_biaopid").html("");
        }
    }
    if ($("#treeceng option:selected").val() == "") {
        $("#valide_treeceng").html("层级不能为空!");
        return false;
    } else {
        $("#valide_treeceng").html("");
    }
    return true;
}

function locationTab4() {
    $('#myTab a[href="#tab_1_1_4"]').tab('show');
}

function locationTab2() {
    $('#myTab a[href="#tab_1_1_2"]').tab('show');
}


//配置tree信息维护
function cleantreecontent() {
    //维护内容清空
    $("#cenguid").val("");
    $("#cenname").val("");
    $("#tablename").empty();
    $("#biaocolumn").val("");
    $("#biaoid").empty();
    $("#biaoname").empty();
    $("#biaopid").empty();

    //验证信息清空
    $("#valide_cenguid").html("");
    $("#valide_cenname").html("");
    $("#valide_tablename").html("");
    $("#valide_biaocolumn").html("");
    $("#valide_biaoid").html("");
    $("#valide_biaoname").html("");
    $("#valide_biaopid").html("");
    $("#valide_treeceng").html("");
}

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function showMsg(text, icon) {
    $.toast().reset('all');
    $.toast({
        text: text,
        icon: icon,
        showHideTransition: 'fade',
        allowToastClose: true,
        hideAfter: 1500,
        stack: false,
        position: 'top-right',
        textAlign: 'left',
        loader: true,
        loaderBg: '#9ec600',
    });
}
